<template>
    <el-dialog
        :visible.sync="visible"
        :title="!dataForm.id ? $t('add') : $t('update')"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
    >
        <el-form
            :model="dataForm"
            ref="dataForm"
            @keyup.enter.native="dataFormSubmitHandle()"
            label-width="30%"
            class="fromStyle"
            inline
        >
            <el-form-item label="房间id" prop="fjId">
                <el-input v-model="dataForm.fjId" placeholder="房间id"></el-input>
            </el-form-item>
            <el-form-item label="交易类型 租赁" prop="transactionType">
                <el-input v-model="dataForm.transactionType" placeholder="交易类型 租赁"></el-input>
            </el-form-item>
            <el-form-item label="客源类型" prop="customerType">
                <el-input v-model="dataForm.customerType" placeholder="客源类型"></el-input>
            </el-form-item>
            <el-form-item label="客户id" prop="customerId">
                <el-input v-model="dataForm.customerId" placeholder="客户id"></el-input>
            </el-form-item>
            <el-form-item label="房源id" prop="houseId">
                <el-input v-model="dataForm.houseId" placeholder="房源id"></el-input>
            </el-form-item>
            <el-form-item label="房源面积" prop="area">
                <el-input v-model="dataForm.area" placeholder="房源面积"></el-input>
            </el-form-item>
            <el-form-item label="业主姓名" prop="ownerName">
                <el-input v-model="dataForm.ownerName" placeholder="业主姓名"></el-input>
            </el-form-item>
            <el-form-item label="业主电话" prop="ownerPhone1">
                <el-input v-model="dataForm.ownerPhone1" placeholder="业主电话"></el-input>
            </el-form-item>
            <el-form-item label="业主电话2" prop="ownerPhone2">
                <el-input v-model="dataForm.ownerPhone2" placeholder="业主电话2"></el-input>
            </el-form-item>
            <el-form-item label="业主合同对象" prop="ownerContract">
                <el-input v-model="dataForm.ownerContract" placeholder="业主合同对象"></el-input>
            </el-form-item>
            <el-form-item label="业主税费" prop="ownerTaxation">
                <el-input v-model="dataForm.ownerTaxation" placeholder="业主税费"></el-input>
            </el-form-item>
            <el-form-item label="业主家具" prop="ownerFurniture">
                <el-input v-model="dataForm.ownerFurniture" placeholder="业主家具"></el-input>
            </el-form-item>
            <el-form-item label="业主价格" prop="ownerPrice">
                <el-input v-model="dataForm.ownerPrice" placeholder="业主价格"></el-input>
            </el-form-item>
            <el-form-item label="业主佣金" prop="ownerCommission">
                <el-input v-model="dataForm.ownerCommission" placeholder="业主佣金"></el-input>
            </el-form-item>
            <el-form-item label="业主付款方式" prop="ownerPayType">
                <el-input v-model="dataForm.ownerPayType" placeholder="业主付款方式"></el-input>
            </el-form-item>
            <el-form-item label="业主押金" prop="ownerDeposit">
                <el-input v-model="dataForm.ownerDeposit" placeholder="业主押金"></el-input>
            </el-form-item>
            <el-form-item label="业主免租期" prop="ownerFreeTime">
                <el-input v-model="dataForm.ownerFreeTime" placeholder="业主免租期"></el-input>
            </el-form-item>
            <el-form-item label="业主合同年限" prop="ownerContractTime">
                <el-input v-model="dataForm.ownerContractTime" placeholder="业主合同年限"></el-input>
            </el-form-item>
            <el-form-item label="业主递增" prop="ownerIncrease">
                <el-input v-model="dataForm.ownerIncrease" placeholder="业主递增"></el-input>
            </el-form-item>
            <el-form-item label="客户姓名" prop="customerName">
                <el-input v-model="dataForm.customerName" placeholder="客户姓名"></el-input>
            </el-form-item>
            <el-form-item label="客户电话1" prop="customerPhone1">
                <el-input v-model="dataForm.customerPhone1" placeholder="客户电话1"></el-input>
            </el-form-item>
            <el-form-item label="客户电话2" prop="customerPhone2">
                <el-input v-model="dataForm.customerPhone2" placeholder="客户电话2"></el-input>
            </el-form-item>
            <el-form-item label="业主合同对象" prop="csutomerContract">
                <el-input v-model="dataForm.csutomerContract" placeholder="业主合同对象"></el-input>
            </el-form-item>
            <el-form-item label="客户价格" prop="customerPrice">
                <el-input v-model="dataForm.customerPrice" placeholder="客户价格"></el-input>
            </el-form-item>
            <el-form-item label="业主税费" prop="csutomerTaxation">
                <el-input v-model="dataForm.csutomerTaxation" placeholder="业主税费"></el-input>
            </el-form-item>
            <el-form-item label="客户家具" prop="csutomerFurniture">
                <el-input v-model="dataForm.csutomerFurniture" placeholder="客户家具"></el-input>
            </el-form-item>
            <el-form-item label="客户需求面积" prop="customerArea">
                <el-input v-model="dataForm.customerArea" placeholder="客户需求面积"></el-input>
            </el-form-item>
            <el-form-item label="客户佣金" prop="customerCommission">
                <el-input v-model="dataForm.customerCommission" placeholder="客户佣金"></el-input>
            </el-form-item>
            <el-form-item label="客户付款方式" prop="customerPayType">
                <el-input v-model="dataForm.customerPayType" placeholder="客户付款方式"></el-input>
            </el-form-item>
            <el-form-item label="客户押金" prop="customerDeposit">
                <el-input v-model="dataForm.customerDeposit" placeholder="客户押金"></el-input>
            </el-form-item>
            <el-form-item label="客户免租期" prop="customerFreeTime">
                <el-input v-model="dataForm.customerFreeTime" placeholder="客户免租期"></el-input>
            </el-form-item>
            <el-form-item label="客户合同年限" prop="customerContractTime">
                <el-input v-model="dataForm.customerContractTime" placeholder="客户合同年限"></el-input>
            </el-form-item>
            <el-form-item label="客户递增" prop="customerIncrease">
                <el-input v-model="dataForm.customerIncrease" placeholder="客户递增"></el-input>
            </el-form-item>
            <el-form-item label="意向单状态" prop="state">
                <el-input v-model="dataForm.state" placeholder="意向单状态"></el-input>
            </el-form-item>
            <el-form-item label="是否外佣" prop="external">
                <el-input v-model="dataForm.external" placeholder="是否外佣"></el-input>
            </el-form-item>
            <el-form-item label="是否重点单" prop="important">
                <el-input v-model="dataForm.important" placeholder="是否重点单"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
            </el-form-item>
            <el-form-item label="部门id" prop="deptId">
                <el-input v-model="dataForm.deptId" placeholder="部门id"></el-input>
            </el-form-item>
            <el-form-item label="城市租户编码" prop="tenantCode">
                <el-input v-model="dataForm.tenantCode" placeholder="城市租户编码"></el-input>
            </el-form-item>
            <el-form-item label="删除状态" prop="deleteFlag">
                <el-input v-model="dataForm.deleteFlag" placeholder="删除状态"></el-input>
            </el-form-item>
            <el-form-item label="修改人" prop="updater">
                <el-input v-model="dataForm.updater" placeholder="修改人"></el-input>
            </el-form-item>
            <el-form-item label="修改时间" prop="updateDate">
                <el-input v-model="dataForm.updateDate" placeholder="修改时间"></el-input>
            </el-form-item>
        </el-form>
        <template slot="footer">
            <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
            <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
        </template>
    </el-dialog>
</template>

<script>
import debounce from "lodash/debounce";
export default {
    data() {
        return {
            visible: false,
            dataForm: {
                id: "",
                fjId: "",
                transactionType: "",
                customerType: "",
                customerId: "",
                houseId: "",
                area: "",
                ownerName: "",
                ownerPhone1: "",
                ownerPhone2: "",
                ownerContract: "",
                ownerTaxation: "",
                ownerFurniture: "",
                ownerPrice: "",
                ownerCommission: "",
                ownerPayType: "",
                ownerDeposit: "",
                ownerFreeTime: "",
                ownerContractTime: "",
                ownerIncrease: "",
                customerName: "",
                customerPhone1: "",
                customerPhone2: "",
                csutomerContract: "",
                customerPrice: "",
                csutomerTaxation: "",
                csutomerFurniture: "",
                customerArea: "",
                customerCommission: "",
                customerPayType: "",
                customerDeposit: "",
                customerFreeTime: "",
                customerContractTime: "",
                customerIncrease: "",
                state: "",
                external: "",
                important: "",
                remark: "",
                deptId: "",
                tenantCode: "",
                deleteFlag: "",
                creator: "",
                createDate: "",
                updater: "",
                updateDate: ""
            }
        };
    },
    methods: {
        init() {
            this.visible = true;
            this.$nextTick(() => {
                this.$refs["dataForm"].resetFields();
                if (this.dataForm.id) {
                    this.getInfo();
                }
            });
        },
        // 获取信息
        getInfo() {
            this.$http
                .get(`/intention/intentionleaseinfo/${this.dataForm.id}`)
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.dataForm = {
                        ...this.dataForm,
                        ...res.data
                    };
                })
                .catch(() => {});
        },
        // 表单提交
        dataFormSubmitHandle: debounce(
            function() {
                this.$refs["dataForm"].validate(valid => {
                    if (!valid) {
                        return false;
                    }
                    this.$http[!this.dataForm.id ? "post" : "put"](
                        "/intention/intentionleaseinfo/",
                        this.dataForm
                    )
                        .then(({ data: res }) => {
                            if (res.code !== 0) {
                                return this.$message.error(res.msg);
                            }
                            this.$message({
                                message: this.$t("prompt.success"),
                                type: "success",
                                duration: 500,
                                onClose: () => {
                                    this.visible = false;
                                    this.$emit("refreshDataList");
                                }
                            });
                        })
                        .catch(() => {});
                });
            },
            1000,
            { leading: true, trailing: false }
        )
    }
};
</script>
